package com.zjw.register.controller;

import com.zjw.model.R;
import com.zjw.model.enums.ClientType;
import com.zjw.model.pojo.vo.WsNodeInfo;
import com.zjw.model.pojo.vo.WsNotifyVO;
import com.zjw.register.service.RegisterService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Map;

@RestController
@RequestMapping("/ws")
public class RegisterController {

    @Resource
    private RegisterService registerService;

    @PostMapping("/register")
    public R<Void> register(@RequestBody WsNotifyVO notifyVO) {
        return registerService.register(notifyVO);
    }

    @GetMapping("/getServersByUserId")
    public R<Collection<WsNodeInfo>> getServersByUserId(@RequestParam String groupId, @RequestParam String userId) {
        return registerService.getServersByUserId(groupId, userId);
    }

    @GetMapping("/getServerByClientType")
    public R<WsNodeInfo> getServerByClientType(@RequestParam String groupId, @RequestParam String userId, @RequestParam ClientType clientType) {
        return registerService.getServerByClientType(groupId, userId, clientType);
    }

    @GetMapping("/getServers")
    public R<Map<String, Map<String, Map<ClientType, WsNodeInfo>>>> getServers(){
        return registerService.getServers();
    }
}
